/*
 * AnimSprite.h
 *
 *  Created on: Aug 2, 2009
 *      Author: kurt
 */

#ifndef ANIMSPRITE_H_
#define ANIMSPRITE_H_

#include "Sprite.h"
#include <vector>

namespace objdraw {

class AnimSprite: public objdraw::Sprite 
{
	protected:
		bool animating;
		bool loop;
		/** rewind on finish if true */
		bool reof;
		float speed;
		std::vector<uint> aniFrames;
		uint cFrameIndex;
		
		u32 tickResolution;
		u64 tickLast;
		
		virtual ~AnimSprite();
	public:
		AnimSprite();
		AnimSprite(Image * img, DrawingCanvas * c = NULL, bool auto_del = false);
		
		virtual void setAniFrames(std::vector<uint> frames) { aniFrames = frames; }
		virtual void setAniFrames(uint start, uint end);
		
		virtual void setSpeed(float _speed) { speed = _speed; }
		virtual float getSpeed() { return speed; }
		
		virtual bool isAnimating() { return animating; }
		virtual bool toggleAnim() { return (animating = !animating); }
		virtual void startAnim() { animating = true; }
		virtual void stopAnim() { animating = false; }
		virtual void rewind() { setFrame(aniFrames.at((cFrameIndex = 0))); }
		
		virtual bool autoLoop() { return loop; }
		virtual void setAutoLoop(bool _loop) { loop = _loop; }
		
		virtual bool rewindOnFinish() { return reof; }
		virtual void rewindOnFinish(bool _rw) { reof = _rw; }
		
		virtual uint getAniFrame(uint f) { return aniFrames.at(f); }
		virtual uint getAniFrame() { return aniFrames.at(cFrameIndex); }
		
		virtual void update();
};

}

#endif /* ANIMSPRITE_H_ */
